package com.threeonemeeting.activity;

import java.io.File;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;

import com.threeonemeeting.R;
import com.threeonemeeting.adapter.FileListAdapter;

public class SelectImageFromSDActivity extends SelectFileActivity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		ListView fileListView = (ListView) findViewById(R.id.file_list);
		fileListView.setOnItemClickListener(new OnItemClickListener() {

			@SuppressWarnings("rawtypes")
			public void onItemClick(AdapterView parent, View view,
					int position, long id) {

				ListView fileListView = (ListView) findViewById(R.id.file_list);
				FileListAdapter fileListAdapter = (FileListAdapter) fileListView
						.getAdapter();

				if (fileListAdapter != null) {
					File file = fileListAdapter.getItem(position);
					if (file.isDirectory()) {
						fill(file);

						TextView pathView = (TextView) findViewById(R.id.current_path);
						pathView.setText(file.getAbsolutePath());
						currentFile = file;
					} else {

						String pathStr = file.getAbsolutePath();

						Intent intent = new Intent(
								SelectImageFromSDActivity.this,
								TabHomeActivity.class);
						intent.putExtra("path", pathStr);
						SelectImageFromSDActivity.this.setResult(RESULT_OK,
								intent);

						finish();
					}
				}
			}
		});
	}

}
